﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//请先添加引用
using System.Configuration;
using System.Collections.Generic;
/// <summary>
/// AspPager 的摘要说明
/// </summary>
///

namespace Usas.DAL.Cms
{
    public class AspPager
    {
        public AspPager()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        public int Size()
        {
            try
            {
                return Convert.ToInt32(ConfigurationManager.AppSettings["PageSize"]);
            }
            catch
            {
                return 20;
            }

        }

        public DataSet ShowListDesc(string table, string where, string PK, int num, int index, string col)
        {

            string sql = "select top " + num + " " + col + " from " + table + " where " + PK + "<=(select max(" + PK + ") from" +
                 "(select top " + index + " " + PK + " from " + table + " where " + where + " order by " + PK + ") as t)" +
                 " and " + where + " order by " + PK + " desc";

            return DbHelperSQL.Query(sql);

        }

        public DataSet ShowListDesc(string table, string where, string PK, int num, int index, string col, string by)
        {
            string sql = "select top " + num + " " + col + " from " + table + " where " + by + "<=(select max(" + by + ") from" +
                 "(select top " + index + " " + by + " from " + table + " where " + where + " order by " + by + " asc) as t)" +
                 " and " + where + " order by " + by + " desc";
            return DbHelperSQL.Query(sql);

        }


        public int ShowListCount(string table, string where, string PK)
        {
            string sql = "select count(" + PK + ") from " + table + " where " + where;

            return Convert.ToInt32(DbHelperSQL.GetSingle(sql));

        }

        public DataSet ShowListAsc(string table, string where, string PK, int num, int index, string col)
        {

            string sql = "select top " + num + " " + col + " from " + table + " " +
                            "where (" + PK + ">=(select min(" + PK + ") from " +
                            "(select top " + index + " " + PK + " from " + table + " " +
                            "where " + where + " order by " + PK + " desc) as t)) and " + where + "order by " + PK + " asc";
            return DbHelperSQL.Query(sql);
        }

        public int TranSql(List<string> ls)
        {
            return DbHelperSQL.ExecuteSqlTran(ls);
        }
    }
}
